<?php
	require_once 'loginSuccess.php';
	
	if(isset($_GET["id"])) {
		$albumId = $_GET["id"];
		if(!isset($_GET['picName'])) {
			displayPics($albumId);
		}
		else {
			$name = $_GET['picName'];
			displaySinglePic($name);
		}
	}
	function displaySinglePic($name) {
		echo "<image src='images/$name' />";
	}
	
	function displayPics($albumId) {
		global $dbConnection;
		$query = "Select name
				From images
				where albumId = $albumId";
		$statement = $dbConnection->execute($query);
		echo "<table><tr>";
		$i = 1;
		while($row = $statement->fetch_row()) {
			$currentPic = $row[0];
			echo "<td><a href='?id=$albumId&picName=$currentPic'><image src='images/$currentPic' style='width:150px;height:150px;'/></a><td>";
			if($i % 5 == 0) {
				echo "</tr><tr>";
			}
			$i++;
		}
		echo "</tr></table>";
	}
	
?>